import 'package:flutter/material.dart';

class MTBody extends StatefulWidget {
  const MTBody({Key? key, required this.list}) : super(key: key);

  final List list;

  @override
  _MTBodyState createState() => _MTBodyState();
}

class _MTBodyState extends State<MTBody> {
  int _activeIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: const Color.fromRGBO(255, 245, 230, 1),
      width: double.infinity,
      height: double.infinity,
      child: Row(
        children: [
          Container(
            width: 120, // ListView必须放在有宽度的容器中
            color: const Color.fromARGB(255, 209, 206, 206),
            child: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return GestureDetector(
                  onTap: () {
                    setState(() {
                      _activeIndex = index;
                    });
                  },
                  child: Container(
                    color: _activeIndex == index
                        ? Colors.white
                        : const Color.fromARGB(255, 209, 206, 206),
                    height: 80,
                    alignment: Alignment.center,
                    child: Text(widget.list[index]["name"]),
                  ),
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return Container(
                  // width: double.infinity,
                  height: 1,
                  color: Colors.white,
                );
              },
              itemCount: widget.list.length,
            ),
          )
        ],
      ),
    );
  }
}
